package com.eml.service.dao.impl;

import com.eml.service.dao.OrderDao;
import com.eml.service.entity.Orders;
import com.eml.service.util.JDBCUtils;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class OrdersDaoImpl implements OrderDao {
    //查询订单信息
    @Override
    public Orders selectOrder(Integer orderId) throws Exception {
        Connection conn = JDBCUtils.getConnection();
        String sql="select money,pay_time,finish_time from order where order_id=?";
        PreparedStatement psmt = conn.prepareStatement(sql);
        psmt.setInt(1,orderId);
        ResultSet rs = psmt.executeQuery();
        if (rs.next()){
            int money=rs.getInt("money");
            Date payTime = rs.getDate("pay_time");
            Date finishTime = rs.getDate("finish_time");
            return new Orders(money,payTime,finishTime);
        }
        JDBCUtils.close(conn,psmt,rs);
        return null;
    }

    @Override
    public void insertOrder() throws Exception {

    }

    @Override
    public void updateOrder(int orderId) throws Exception {

    }
}
